package com.scqzy.shengchunqiang.sword2offer.day08;

/**
 * @Description: 剑指 Offer 63. 股票的最大利润
 * @Author 盛春强
 * @Date 2021/8/15 15:49
 */
public class MaxProfit {
    public int maxProfit(int[] prices) {
        if (prices.length == 0) {
            return 0;
        }
        int profit = 0;
        int min = prices[0];
        for (int i = 1; i < prices.length; i++) {
            if (prices[i] < min) {
                min = prices[i];
            } else {
                profit = Math.max(profit,prices[i] - min);
            }
        }
        return profit;
    }
}
